/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.click.app.dao.hibernate;

import com.click.app.Functions;
import com.click.app.dao.ProductDao;
import com.click.app.model.EntryProduct;
import com.click.app.model.EntryProductDetail;
import com.click.app.model.LabelValue;
import com.click.app.model.Product;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author arnold
 */
public class ProductDaoHibernate extends GenericDaoHibernate<Product, Long> implements ProductDao {

    List<LabelValue> productLabelValueList;

    public ProductDaoHibernate() {
        super(Product.class);
    }

    public List<Product> findById(Long id) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public List<EntryProductDetail> getListEntryProductDetails() {
        return super.getHibernateTemplate().find("from EntryProductDetail");

    }

    public Float getHighestPrice(Product p){
        Float hp=0.0f;
            for (EntryProductDetail ep:getListEntryProductDetails()){
                if (p.getId()==(ep.getProduct().getId())){
                    if (ep.getSellPrice()>hp){
                        hp=ep.getSellPrice();
                    }
                }
            }
            return hp;
    }

    public List<Product> getAllPrices() {
        List<Product> listProducts = getAll();

        return listProducts;
    }

    public List<LabelValue> getAllLabelValue() {
        if (productLabelValueList == null) {
            List<Product> listProducts = getAll();
            productLabelValueList = new ArrayList<LabelValue>();
            for (Product m : listProducts) {
                productLabelValueList.add(new LabelValue(m.getName(), m.getId().toString()));
            }
        }
        return productLabelValueList;
    }

    public List<Product> findProductByFeatureProduct(List<String> names, List<String> operatorNames, List<String> values, List<String> operatorValues, List<String> joinsFields) {
        List listProducts = getHibernateTemplate().find("Select product from Product product inner join product.listFeatureProducts as featureProduct " +
                " where " + Functions.generateFilter(names, operatorNames, values, operatorValues, "featureProduct.name", "featureProduct.description", joinsFields));
        return listProducts;
    }
}

